<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<?php echo header("Access-Control-Allow-Origin: *");?>
	<title></title>
	<script type="text/javascript" src="Public/org/jquery.js"></script>
	<script type="text/javascript" src="Public/org/hdjs/hdjs.min.js"></script>
	<link rel="stylesheet" type="text/css" href="Public/org/hdjs/hdjs.css"/>
	<link rel="stylesheet" type="text/css" href="Public/org/home/css/myCart.css"/>
	<style type="text/css">
	.modalLog {
	  background: #fafafa;
	  padding-bottom: 50px;
	  /*border:1px solid red;*/
	}
	.modalLog form {
	  width: 272px;
	  margin: 0 auto;
	  padding: 10px 20px 10px;
	}
	.modalLog form p{
	  margin-top: 10px;
	  width: 100%;
	  overflow: hidden;
	  vertical-align: middle;
	}
	.modalLog form p span {
	  display: block;
	  float: left;
	  line-height: 28px;
	}
	.modalLog form p input {
	  width: 227px;
	  height: 28px;
	  border: 1px solid #A5AFC3;
	  text-indent: 5px;
	  color: #999999;
	  float: left;
	}
	.modalLog form p input.pwd {
	  width: 227px;
	}
	#hd-modal{
		border:1px solid #a10000;border-radius: 0;
	}
	.modalLog button {
	  margin: 2px 0 0px 42px;
	  border: 0;
	  width: 97px;
	  height: 27px;
	  color: #fff;
	  border-radius: 3px;
	  background: #a10000;
	}
}
</style>	
</head>
<body>
	<!--顶部-->
		<header>
			<div class="nav">
				<img alt="凡客诚品" src="http://i2.vanclimg.com/cms/20140829/vancl-logo.png">
				<p>您好,
					<?php if(!isset($_SESSION['id'])):?>
                    <a href="javascript:hd_modal_test();">登录</a>
                    |
                    <a href="index.php?m=Home&c=Reg&a=reg">注册</a>
            <?php else:?>
                <?php echo $_SESSION['nickname']?>
                    <a style="color:#a10000;" href="index.php?m=Home&c=Index&a=out">退出登录</a>
                    |
                    <a style="color:#a10000;" href="index.php?m=Home&c=Index&a=changeuser">更换用户</a>
            <?php endif;?>
				</p>				
			</div>	
			<!--进度-->
			<div class="flow">
				<span class="active">1.我的购物车</span>
				<span>2.填写核对信息单</span>
				<span>3.成功提交订单</span>
			</div>
			<!--进度结束-->
		</header>
		<!--顶部 end-->
		
		<!-- 购物车内容页 -->
		<div class="cartContentArea">
			
			<div class="cartContent">
				<!-- 我的购物车与提示消息 -->
				<div class="title">
					<p class="con">我的购物车</p>
					<p class="cartMsg">	
					  <span>温馨提示：</span>
					  1.选购清单中的商品无法保留库存，请您及时结算。2.商品的价格和库存将以订单提交时为准。3.促销活动满减优惠将均摊至商品小计中。
					</p>
				</div>
				<!-- 我的购物车与提示消息end -->

				<!-- 购物车内商品信息 -->
				<div class="bill">
				<form method="post" action="<?php echo U('Pay/pay')?>" id="pay">
					<table>
						<thead>
							<tr>
								<th class="ml"></th>
								<th class="title">
									<label><input type="checkbox" checked="checked" id="checkall" onclick="allcheck(this)">全选</label>
								</th>
								<th class="img"></th>
								<th class="name">商品名称</th>
								<th class="size">尺寸</th>
								<th class="price">单价</th>
								<th class="num">数量</th>
								<th class="mintotal">小计</th>
								<th class="option">操作</th>
								<th class="mr"></th>
							</tr>
						</thead>
						<tbody>
						<?php foreach($data as $key => $field):?>
							<tr class="goodsline">
							<input type="hidden" name="goods_id" value="<?php echo $field['goods_id']?>">						
								<td class="white"></td>
								<td class="" style="text-align:center;">
									<input type="checkbox" name="goods[]" value="<?php echo $key?>" checked="checked">
								</td>
								<td class=""><img src="<?php echo $field['thumb_pic']?>"></td>
								<td class="pd">
									<a href="<?php echo U('Detail/show',array('goods_id'=>$field['goods_id']))?>"><?php echo $field['goods_name']?></a></td>
								<td class="center"><a class="size" href=""><?php echo $field['size']?></a></td>
								<td class="center min"><?php echo $field['price']?></td>
								<td class="center total">
									<a href="javascript:;" onclick="down(this)" class="down">-</a>
									<input style="text-align: center" type="text" class="lock" value="<?php echo $field['total']?>">
									<a href="javascript:;" onclick="up(this)" class="up">+</a>									
								</td>
								<td class="center price"><?php echo $field['minprice']?></td>
								<td class="center"><a href="javascript:;" onclick="del(this)">删除</a></td>
								<td class="white"></td>
							</tr>
							<tr class="null"></tr>
						<?php endforeach;?>
						</tbody>
					</table>
					</form>
				</div>
				<!-- 购物车内商品信息end -->
				<!-- 结算信息 -->
				<div class="payBill">
					<p>
						<input type="checkbox" checked="checked" id="cancelall"><label for="cancelall">全选</label>
						<a href="">删除</a>
						<span>数量总计：<strong id="sum">1</strong>件 </span>
					</p>
					<section class="billMsg">
						产品金额总计(不含运费)：
						<span>
							￥<strong id="cash"></strong>
						</span>
					</section>
					<section class="btn">
						<a href="<?php echo __WEB__?>" class="back"><<继续购物</a>
						<button onclick="push()" type="button" class="next" style="border:0;width: 160px;">去结算>></button>
					</section>
				</div>
				<!-- 结算信息end -->
			</div>
			
		</div>
		
		<!-- 购物车内容页end -->

		<!--页脚-->
    	<footer style="margin-top: 30px;border:0;">
    		<p class="copyRight" style="color:#999;">Copyright 2007 - 2014 vancl.com All Rights Reserved 京ICP证100557号 京公网安备11011502002400号 出版物经营许可证新出发京批字第直110138号</p>
    		<div class="iconMsg">
    			<section class="iconDetail">
    				<a href="#" class="one"></a>
    				<a href="#" class="two"></a>
    				<a href="#" class="three"></a>
    				<a href="#" class="four"></a>
    				<a href="#" class="five"></a>
    				<a href="#" class="six"><img src="Public/org/home/images/kexin_brand_for_others.png"/></a>
    			</section>
    		</div>
    	</footer>
    <!--页脚end-->
</body>
<!-- 商品加减 -->
<script type="text/javascript">
//点击增加事件
function up(obj)
{
	var input = $(obj).parents('.goodsline').eq(0).find('.lock');
	var goods_id = $(obj).parents('.goodsline').eq(0).find('input[name=goods_id]').val();
	var num = input.val()*1+1;
	var minprice = $(obj).parents('.goodsline').eq(0).find('.min').html()*1 * num;
	var size = $(obj).parents('.goodsline').eq(0).find('.size').html();
	// 写入value值
	input.val(num);
	//发到购物车页面
	$.post('index.php?m=Home&c=Cart&a=cart',{goods_id:goods_id,cartnum:num,},function(data){
		input.val(data.total);
		$(obj).parents('.goodsline').eq(0).find('.price').html(data.price);
	});
	//发到购物车更改数据
	$.post('index.php?m=Home&c=Cart&a=joinCart',{goods_id:goods_id,cartnum:num,minprice:minprice,size:size});
	all();
	//即时显示总价加减
	var cash = 0;
	$('.goodsline').each(function(){
		cash += $(this).find('.min').html()*1 * $(this).find('.lock').val();
	});
	$('#cash').html(cash);
}

//点击减少事件
function down(obj)
{
	var input = $(obj).parents('.goodsline').eq(0).find('.lock');
	var goods_id = $(obj).parents('.goodsline').eq(0).find('input[name=goods_id]').val();
	var num = input.val()*1-1;
	var minprice = $(obj).parents('.goodsline').eq(0).find('.min').html()*1 * num;
	var size = $(obj).parents('.goodsline').eq(0).find('.size').html();
	//即时显示总价加减
	var cash = 0;
	$('.goodsline').each(function(){
		cash += ($(this).find('.min').html()*1) * $(this).find('.lock').val();
	});
	$('#cash').html(cash);
	// 判断商品不能减到0			
	if(num==0){		
		alert('您好，商品数量默认不能为0件');
		return false;
	}
	// 写入value值
	input.val(num);
	// 发到购物车页面
	$.post('index.php?m=Home&c=Cart&a=cart',{goods_id:goods_id,cartnum:num},function(data){
		input.val(data.total);
		$(obj).parents('.goodsline').eq(0).find('.price').html(data.price);		
	});
	// 发到购物车更改数据
	$.post('index.php?m=Home&c=Cart&a=joinCart',{goods_id:goods_id,cartnum:num,minprice:minprice,size:size});
	// 同时执行计算函数
	all();
	
}
</script>
<!-- 商品加减end -->

<!-- 每次点击计算件数 -->
<script type="text/javascript">
function all(){
	var sum = 0;
	$('.goodsline').each(function(){
		sum += $(this).find('.lock').val()*1;		
	});
	$('#sum').html(sum);	
}
</script>
<!-- 每次点击计算件数end -->

<!-- 进来就获取数据 -->
<script type="text/javascript">
$(function(){
		var sum = 0;
		var cash = 0;
	$('.goodsline').each(function(){
			sum += $(this).find('.lock').val()*1;
			cash += $(this).find('.price').html()*1;		
		});
		$('#sum').html(sum);
		$('#cash').html(cash);
});
</script>
<!-- 进来获取数据end -->
<!-- 删除单条购物车数据方法 -->
<script type="text/javascript">
	function del(obj)
	{
		var del_id= $(obj).parents('.goodsline').eq(0).find('input[name=goods_id]').val();

		if(confirm('你确定要删除吗?'))
		{
			$.post('index.php?m=Home&c=Cart&a=del',{del_id:del_id},function(data){
				if(data.code==true)
				{
					$(obj).parents('.goodsline').remove();
					location.href=location.href;
				}
			});
		}
	}
</script>
<!-- 删除单条购物车数据方法end -->

<script type="text/javascript">
	function allcheck(obj)
	{
		$("input[type=checkbox]").prop('checked',$(obj).prop('checked'));
	}
</script>

<script>
var section = "<section class='modalLog'>";
section += "<form method='post'><p><span>用户名:</span><input type='text' name='username' value='' required placeholder='Email/手机号' /></p><p><span>密&nbsp;码:</span><input class='pwd' type='password' value='' required name='password' /></p></form><button onclick='login(this)' type='button'>登录</button></section>";
    function hd_modal_test() {
        hd_modal({
            width: 400,//宽度
            height: 250,//高度
            title: '请您登录后再结算',//标题
            content: section,//提示信息
            button: true,//显示按钮
            // button_success: "登录",//确定按钮文字
            // button_cancel: "退出",//关闭按钮文字
            timeout: 0,//自动关闭时间 0：不自动关闭
            shade: true,//背景遮罩
            shadeOpacity: 0.3,//背景透明度
            success: function () {//点击确定后的事件
            	
            },
            cancel: function () {//点击关闭后的事件

            }
        });
    }
</script>

<!-- 提交触发 -->
<script type="text/javascript">
	function push()
	{
		var userid = "<?php echo $userid?>";
		if(userid==0)
		{
			hd_modal_test();
			return false;
			
		}
		$('#pay').submit();
	}

	function login(obj)
	{
		var username = $(obj).parents('.modalLog').find('[name=username]').val(); 
    	var password = $(obj).parents('.modalLog').find('[name=password]').val();
    	$.post('index.php?m=Home&c=Login&a=cartSign',{username:username,password:password},function(data){
	        hd_alert({
	            message: data.message,//显示内容
	            timeout: 1,//显示时间
	            success: function () {//这是回调函数
	            	//刷新一下页面
	        		location.href = location.href;  
	            }
	        });	
	              
    	})
	}
</script>
<!-- 提交触发end -->
</html>
